package com.itheima.API;

import java.util.Scanner;

public class Demo25StringBuilder {
    //通过STringBUilder遍历数组
    public static String arrayPrint(int[] arr) {
        StringBuilder sb = new StringBuilder("[");
        for(int i = 0; i < arr.length; i++) {
            if(i == (arr.length-1)) {
                sb.append(arr[i]);
                sb.append("]");
            }else {
                sb.append(arr[i]);

                sb.append(",");
            }
        }
        String s = sb.toString();
        return s;
    }
    //字符串反转
    public static String reverse(String s) {
        return new StringBuilder(s).reverse().toString();
    }

    public static void main(String[] args) {
        int[] arr = {1,2,3};
        String s = arrayPrint(arr);
        System.out.println(s);

        Scanner sc = new Scanner(System.in);
        String s1 = sc.nextLine();
        StringBuilder sb = new StringBuilder(s1);
        System.out.println(sb.reverse());
    }
}
